* Program to compute ASL of difference of means using naive moving block bootstrap
* and dummy-variable regressions with HAC-corrected standard errors
* for statistical detrending procedures showing consistent improvement.

* This program: Uses 1966-1997 vs. 1998-2006 sample, RMSE-based NSRs,
* and looks at Beveridge-Nelson gaps


calendar 1947 1 4
allocate 2020:04+5000


open data table2_reg_test_data.rat
data(format=rats) / bn_revgapsq_f32 bn_revgapsq_f09


set bn_revgapsq 1966:01 1997:04 = bn_revgapsq_f32
set bn_revgapsq 1998:01 2006:04 = bn_revgapsq_f09


seed 43892



* Set bootstrap and related parameters

compute ndraws=5000
compute nblocks=4
compute haclags=4
set t_ovn_rmse = %NA


set dum98q1 = 0.0
set dum98q1 1998:01 2006:04 = 1.0

linreg(robusterrors,lags=haclags,lwindow=neweywest) bn_revgapsq
# constant dum98q1


statistics(noprint) bn_revgapsq 1966:01 1997:04
compute mean1=%mean
statistics(noprint) bn_revgapsq 1998:01 2006:04
compute mean2=%mean
statistics(noprint) bn_revgapsq 1966:01 2006:04
compute meanfull=%mean

disp "Difference in means = " mean2-mean1


set zzz 1966:01 1997:04 = bn_revgapsq-mean1+meanfull
set yyy 1998:01 2006:04 = bn_revgapsq-mean2+meanfull


do iter=1,ndraws

  set b_zzz = %NA
  set b_yyy = %NA

  boot(replace,block=nblocks,method=overlap) b_entry1 1966:01 1997:04
  set b_zzz = zzz(b_entry1)

  boot(replace,block=nblocks,method=overlap) b_entry2 1998:01 2006:04
  set b_yyy = yyy(b_entry2)

  linreg(robusterrors,lags=haclags,lwindow=neweywest,noprint) b_zzz
  # constant
  compute mean_bzzz=%beta(1)
  compute se_bzzz=%stderrs(1)

  linreg(robusterrors,lags=haclags,lwindow=neweywest,noprint) b_yyy
  # constant
  compute mean_byyy=%beta(1)
  compute se_byyy=%stderrs(1)

  set t_ovn_rmse iter iter = (mean_byyy-mean_bzzz)/sqrt((se_bzzz**2.0)+(se_byyy**2.0))


end do iter


statistics(fract) t_ovn_rmse


